﻿package mortal.game.view.group.cellRenderer
{
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class NearTeamCellRenderer extends GCellRenderer
    {
        private var _sgroup:SGroup;
        private var _teamName:GTextFiled;
        private var _canptain:GTextFiled;
        private var _num:GTextFiled;
        private var _heightestPower:GTextFiled;
        private var _operBtn:GButton;

        public function NearTeamCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._teamName = UIFactory.gTextField("", -22, 0, 160, 20, this, _loc_1);
            this._num = UIFactory.gTextField("", 284, 0, 100, 20, this, _loc_1);
            this._heightestPower = UIFactory.gTextField("", 393, 0, 200, 20, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatChen;
            _loc_1.align = AlignMode.CENTER;
            this._canptain = UIFactory.gTextField("", 107, 0, 160, 20, this, _loc_1);
            this._operBtn = UIFactory.gButton(Language.getString(30226), 654, -1, 67, 22, this);
            this._operBtn.configEventListener(MouseEvent.CLICK, this.applyJoin);
            this.pushUIToDisposeVec(UIFactory.bg(0, 25, 760, 1, this, ImagesConst.SplitLine));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._teamName.dispose(param1);
            this._canptain.dispose(param1);
            this._num.dispose(param1);
            this._heightestPower.dispose(param1);
            this._operBtn.dispose(param1);
            this._teamName = null;
            this._canptain = null;
            this._num = null;
            this._heightestPower = null;
            this._operBtn = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function applyJoin(event:MouseEvent) : void
        {
            var _loc_2:* = new Array();
            var _loc_3:* = new SGroupOper();
            _loc_3.fromEntityId = Cache.instance.role.entityInfo.entityId;
            _loc_3.toEntityId = this._sgroup.captainId;
            _loc_3.fromPlayer = new SPublicPlayer();
            _loc_3.fromPlayer.guildId = new SEntityId();
            _loc_3.fromPlayer.copyId = new SEntityId();
            _loc_3.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
            _loc_3.type = EGroupOperType._EGroupOperTypeApply;
            _loc_3.copyCode = this._sgroup.copyCode;
            _loc_2.push(_loc_3);
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupApplyOper, _loc_2));
            return;
        }// end function

        private function getCaptainName(param1:SEntityId) : String
        {
            var _loc_3:String = null;
            var _loc_4:SGroupPlayer = null;
            var _loc_2:* = this._sgroup.players;
            for each (_loc_4 in _loc_2)
            {
                
                if (EntityUtil.equal(_loc_4.player.entityId, param1))
                {
                    _loc_3 = NameUtil.getProxyName(param1) + _loc_4.player.name;
                }
            }
            return _loc_3;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:SPublicPlayer = null;
            var _loc_3:SGroupPlayer = null;
            super.data = param1;
            this._sgroup = param1.data;
            if (this._sgroup)
            {
                if (this._sgroup.copyCode)
                {
                    this._teamName.text = this._sgroup.name + Language.getString(35303);
                }
                else
                {
                    this._teamName.text = this._sgroup.name;
                }
                this._canptain.text = this.getCaptainName(this._sgroup.captainId);
                this._num.text = this._sgroup.players.length >= 5 ? (Language.getString(30223)) : (this._sgroup.players.length + "/5");
                if (this._sgroup.players.length == 5)
                {
                    this._operBtn.mouseEnabled = false;
                    this._operBtn.filters = [FilterConst.colorFilter2];
                }
                else
                {
                    this._operBtn.mouseEnabled = true;
                    this._operBtn.filters = [];
                }
                _loc_2 = new SPublicPlayer();
                for each (_loc_3 in this._sgroup.players)
                {
                    
                    if (_loc_3.player.combat > _loc_2.combat)
                    {
                        _loc_2 = _loc_3.player;
                    }
                }
                this._heightestPower.htmlText = _loc_2.name + "<font color=\'#FF5a00\'>(" + _loc_2.combat + ")</font>";
            }
            return;
        }// end function

    }
}
